package org.come.Jpanel;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import com.updateNew.MyIsif;
import org.come.bean.TeamBean;
import org.come.until.FormsManagement;
import org.come.until.SrcollPanelUI;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.TeamCreateBtn;
import com.tool.tcpimg.UIUtils;



/**
 * 组队主面板 编号：31
 * 
 * @author HGC<br>
 * @time 2019年12月30日 下午12:01:37<br>
 * @class 类名:TeamCreateJpanel<br>
 */
public class TeamCreateJpanel extends JPanel {
    /**
     * 字段名:btnDownOne 下拉按钮1<br>
     * 字段名:btnDownTwo 下拉按钮2<br>
     * 字段名:btnMenuTeam 队伍列表菜单按钮<br>
     * 字段名:btnReleaseTeamMsg 发布队伍信息按钮<br>
     * 
     * @time 2019年12月30日 下午1:53:23<br>
     */
    private TeamCreateBtn  btnMenuTeam,btnReleaseTeamMsg;//btnDownOne, btnDownTwo,

    /**
     * 字段名:scrollPane 队伍信息滚动条<br>
     * 
     * @time 2019年12月30日 下午2:17:04<br>
     */
    private JScrollPane scrollPane;

    private JList<TeamCreateModelJpanel> modelJpanelList;

    private DefaultListModel<TeamCreateModelJpanel> listModel;

    public TeamCreateJpanel() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        this.setPreferredSize(new Dimension(539, 510));
        this.setOpaque(false);
        this.setLayout(null);

        // 关闭按钮事件
        FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 31);
        offBtn.setBounds(539 - 37, 10, 25, 25);
        this.add(offBtn);

        getBtnReleaseTeamMsg();
        getScrollPane();
        getBtnMenuTeam();
        } else {
            this.setPreferredSize(new Dimension(539, 510));
            this.setOpaque(false);
            this.setLayout(null);

            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/hongmu/s74.png", 1, 31);
            offBtn.setBounds(539 - 36, 10, 25, 25);
            this.add(offBtn);

            getBtnReleaseTeamMsg();
            getScrollPane();
            getBtnMenuTeam();
        }
    }

    /**
     * 初始化刷新面板
     * 
     * @time 2019年12月30日 下午5:22:44<br>
     * @param teamBeans
     */
    public void initializeJlist(List<TeamBean> teamBeans) {
//        int nextInt = new Random().nextInt(20);
//        if (teamBeans == null) {
//            teamBeans = new ArrayList<>();
//            for (int i = 0; i < nextInt; i++) {
//                TeamBean teamBean = new TeamBean();
//                teamBean.seteMsg("快来玩" + i);
//                teamBean.seteTeam(i % 3 == 0 ? "克火" : i % 3 == 1 ? "克水" : "无属性");
//                teamBean.seteTask(i % 3 == 0 ? "任务" : i % 3 == 1 ? "PK" : "其他");
//                teamBean.setTeamId(new BigDecimal(i));
//                List<TeamRole> teams = new ArrayList<>();
//                int num = (i % 6 == 0 ? 1 : i % 6);
//                for (int j = 0; j < num; j++) {
//                    TeamRole teamRole = new TeamRole(RoleData.getRoleData().getLoginResult());
//                    teams.add(teamRole);
//                }
//                teamBean.setTeams(teams);
//                teamBeans.add(teamBean);
//            }
//        }
        Component[] components = modelJpanelList.getComponents();
        int num = components.length;
        int length = teamBeans.size();
        if (num >= length) {
            for (int i = 0; i < num; i++) {
                if (i >= teamBeans.size()) {
                    components[i].setVisible(false);
                } else {
                    TeamBean teamBean = teamBeans.get(i);
                    if (components[i] instanceof TeamCreateModelJpanel) {
                        TeamCreateModelJpanel modelJpanel = (TeamCreateModelJpanel) components[i];
                        modelJpanel.showTeamBean(teamBean);
                        if (!modelJpanel.isVisible()) {
                            modelJpanel.setVisible(true);
                        }
                    }
                }
            }
        } else {
            for (int i = 0; i < length; i++) {
                TeamBean teamBean = teamBeans.get(i);
                if (i >= num) {
                    TeamCreateModelJpanel modelJpanel = new TeamCreateModelJpanel();
                    modelJpanel.showTeamBean(teamBean);
                    modelJpanel.setBounds(0, 50 * i, 456, 50);
                    modelJpanelList.add(modelJpanel);
                } else {
                    if (components[i] instanceof TeamCreateModelJpanel) {
                        TeamCreateModelJpanel modelJpanel = (TeamCreateModelJpanel) components[i];
                        modelJpanel.showTeamBean(teamBean);
                        if (!modelJpanel.isVisible()) {
                            modelJpanel.setVisible(true);
                        }
                    }
                }
            }
        }
        modelJpanelList.setPreferredSize(new Dimension(456, 50 * teamBeans.size()));
        scrollPane.getVerticalScrollBar().setValue(0);
        if (!FormsManagement.getframe(31).isVisible()) {
            FormsManagement.showForm(31);
        }
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            String style = MyIsif.getStyle();
            if ("水墨UI".equals(style)) {
                icon = new ImageIcon("inkImg/newbackground/B208.png");
            } else {
                icon = new ImageIcon("inkImg/hongmu/组队平台红木.png");
            }
        }
        g.drawImage(icon.getImage(), 0, 0, 539, 510, null);
    }

//    public TraslationSelectOptionJpanel getRollOne() {
//        if (rollOne == null) {
//            String[] rowData = new String[] { "不限" };
//            rollOne = new TraslationSelectOptionJpanel(65, 101, "inkImg/old/background/S160.png", rowData);
//            rollOne.setBounds(47, 71, 65, 101);
//            rollOne.addMouseListener(new MouseListener() {
//
//                @Override
//                public void mouseReleased(MouseEvent e) {
//                    // TODO Auto-generated method stub
//
//                }
//
//                @Override
//                public void mousePressed(MouseEvent e) {
//                    String value = rollOne.getJlist().getSelectedValue();
//                    if (value != null) {
//
//                    }
//                }
//
//                @Override
//                public void mouseExited(MouseEvent e) {
//                    // TODO Auto-generated method stub
//
//                }
//
//                @Override
//                public void mouseEntered(MouseEvent e) {
//                    // TODO Auto-generated method stub
//
//                }
//
//                @Override
//                public void mouseClicked(MouseEvent e) {
//                    // TODO Auto-generated method stub
//
//                }
//            });
//            rollOne.setVisible(false);
//            this.add(rollOne);
//        }
//        return rollOne;
//    }

//    public void setRollOne(TraslationSelectOptionJpanel rollOne) {
//        this.rollOne = rollOne;
//    }

//    public TraslationSelectOptionJpanel getRollTwo() {
//        if (rollTwo == null) {
//            String[] rowData = new String[] { "综合" };
//            rollTwo = new TraslationSelectOptionJpanel(83, 101, "inkImg/old/background/S161.png", rowData);
//            rollTwo.setBounds(119, 71, 83, 101);
//            rollTwo.setVisible(false);
//            this.add(rollTwo);
//        }
//        return rollTwo;
//    }

//    public void setRollTwo(TraslationSelectOptionJpanel rollTwo) {
//        this.rollTwo = rollTwo;
//    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

//    public TeamCreateBtn getBtnDownOne() {
//        if (btnDownOne == null) {
//            btnDownOne = new TeamCreateBtn("skin/8100226/button/8.png", 1, 0, this);
//            btnDownOne.setBounds(94, 54, 18, 18);
//            this.add(btnDownOne);
//        }
//        return btnDownOne;
//    }

//    public void setBtnDownOne(TeamCreateBtn btnDownOne) {
//        this.btnDownOne = btnDownOne;
//    }

//    public TeamCreateBtn getBtnDownTwo() {
//        if (btnDownTwo == null) {
//            btnDownTwo = new TeamCreateBtn("skin/8100226/button/8.png", 1, 1, this);
//            btnDownTwo.setBounds(184, 54, 18, 18);
//            this.add(btnDownTwo);
//        }
//        return btnDownTwo;
//    }

//    public void setBtnDownTwo(TeamCreateBtn btnDownTwo) {
//        this.btnDownTwo = btnDownTwo;
//    }

//    public JLabel getLabOne() {
//        if (labOne == null) {
//            labOne = new JLabel("不限");
//            labOne.setForeground(Color.white);
//            labOne.setFont(UIUtils.TEXT_FONT1);
//            labOne.setBounds(48, 54, 63, 16);
//            this.add(labOne);
//        }
//        return labOne;
//    }

//    public void setLabOne(JLabel labOne) {
//        this.labOne = labOne;
//    }

//    public JLabel getLabTwo() {
//        if (labTwo == null) {
//            labTwo = new JLabel("综合");
//            labTwo.setForeground(Color.white);
//            labTwo.setFont(UIUtils.TEXT_FONT1);
//            labTwo.setBounds(120, 54, 81, 16);
//            this.add(labTwo);
//        }
//        return labTwo;
//    }

//    public void setLabTwo(JLabel labTwo) {
//        this.labTwo = labTwo;
//    }

    public JScrollPane getScrollPane() {
        if (scrollPane == null) {
            scrollPane = new JScrollPane(getModelJpanelList());
            scrollPane.setBounds(30, 85, 481, 365);
            scrollPane.getViewport().setOpaque(false);
            scrollPane.setOpaque(false);
            scrollPane.setBorder(BorderFactory.createEmptyBorder());
            scrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
            scrollPane.getVerticalScrollBar().setUnitIncrement(60);
            scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            this.add(scrollPane);
        }
        return scrollPane;
    }

    public void setScrollPane(JScrollPane scrollPane) {
        this.scrollPane = scrollPane;
    }

    public JList<TeamCreateModelJpanel> getModelJpanelList() {
        if (modelJpanelList == null) {
            modelJpanelList = new JList<TeamCreateModelJpanel>();
            modelJpanelList.setOpaque(false);
            modelJpanelList.removeAll();
            // modelJpanelList.setCellRenderer(new DefaultListCellRenderer() {
            // @Override
            // public Component getListCellRendererComponent(JList<?> list,
            // Object value, int index,
            // boolean isSelected, boolean cellHasFocus) {
            // if (value instanceof TeamCreateModelJpanel) {
            // TeamCreateModelJpanel modelJpanel = (TeamCreateModelJpanel)
            // value;
            // return modelJpanel;
            // }
            // return super.getListCellRendererComponent(list, value, index,
            // isSelected, cellHasFocus);
            // }
            // });
            // modelJpanelList.setModel(getListModel());
        }
        return modelJpanelList;
    }

    public void setModelJpanelList(JList<TeamCreateModelJpanel> modelJpanelList) {
        this.modelJpanelList = modelJpanelList;
    }

    public DefaultListModel<TeamCreateModelJpanel> getListModel() {
        if (listModel == null) {
            listModel = new DefaultListModel<>();
        }
        return listModel;
    }

    public void setListModel(DefaultListModel<TeamCreateModelJpanel> listModel) {
        this.listModel = listModel;
    }

    public TeamCreateBtn getBtnMenuTeam() {
        if (btnMenuTeam == null) {
            String style = MyIsif.getStyle();
            if ("水墨UI".equals(style)) {
            btnMenuTeam = new TeamCreateBtn("skin/8100226/newbutton/K14.png", 1, 10, this);
            btnMenuTeam.setBounds(66, 21, 95, 33);
            this.add(btnMenuTeam);
            } else {
                btnMenuTeam = new TeamCreateBtn("skin/41104/mobutton/组队红木-100.png", 1, 10, this);
                btnMenuTeam.setBounds(86, 11, 95, 33);
                this.add(btnMenuTeam);
            }
        }
        return btnMenuTeam;
    }

    public void setBtnMenuTeam(TeamCreateBtn btnMenuTeam) {
        this.btnMenuTeam = btnMenuTeam;
    }

	public TeamCreateBtn getBtnReleaseTeamMsg() {
		if(btnReleaseTeamMsg == null){
            String style = MyIsif.getStyle();
            if ("水墨UI".equals(style)) {
			btnReleaseTeamMsg = new TeamCreateBtn("skin/8100226/newbutton/B22.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "发布征召", 0, this);
			btnReleaseTeamMsg.setBounds(219,461, 99, 24);
			this.add(btnReleaseTeamMsg);
            } else {
                btnReleaseTeamMsg = new TeamCreateBtn("inkImg/hongmu/a2.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, "发布征召", 0, this);
                btnReleaseTeamMsg.setBounds(219, 461, 99, 24);
                this.add(btnReleaseTeamMsg);
            }
		}
		return btnReleaseTeamMsg;
	}

	public void setBtnReleaseTeamMsg(TeamCreateBtn btnReleaseTeamMsg) {
		this.btnReleaseTeamMsg = btnReleaseTeamMsg;
	}

}
